import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    meta: {
      title: '首页'
    },
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    meta: {
      title: '关于'
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },
  {
    path: '/tab',
    name: 'Tab',
    meta: {
      title: 'TAB'
    },
    component: () => import('../views/tab/Index.vue')
  }, {
    path: '/part1',
    name: 'part1',
    meta: {
      title: '模块1'
    },
    component: () => import('../views/Part1.vue'),
    children: [{
      path: '/part1/child1',
      name: 'Child1',
      meta: {
        title: '子模块1'
      },
      component: () => import('../views/Part1/Child1.vue')
    },
    {
      path: '/child2',
      name: 'Child2',
      meta: {
        title: '子模块2'
      },
      component: () => import('../views/Part1/Child2.vue')
    }]
  },
  {
    path: '/part2/:id',
    name: 'part2',
    meta: {
      title: '模块2'
    },
    props: {
      pro: {
        a: 'aaa',
        b: 'bn'
      }
    },
    component: () => import('../views/Part2.vue')
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach(function (to, from, next) {
  if (!sessionStorage.getItem('sign')) {
    if (to.path != "/") {
      alert('请打卡');
      next('/');
    } else {
      next();
    }
  } else {
    next();
  };

});

export default router
